Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LF-4564 unnest tasks from animals #3582

Merged
merged 3 commits into from
Dec 6, 2024
Merged

Conversation

antsgar
Copy link
Collaborator

@antsgar antsgar commented Dec 6, 2024

Description

This was initially suggested here #3554 (comment)
Updates logic in the UI that verifies if animals/batches have finalized tasks to check the tasks themselves instead of relying on tasks being nested within animals.
Eliminates nested tasks from animals in API.
Removes need to invalidate animal/batch tags on task creation/deletion.

Jira link:
https://lite-farm.atlassian.net/browse/LF-4564

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have added "MISSING" for all new language tags to languages I don't speak
  • I have added the GNU General Public License to all new files

@Duncan-Brain
Copy link
Collaborator

I am currently seeing that the created in error option is not shown for all animals.... looking into it.

I like this solution! I think Sayakas concern was with efficiency of querying tasks. My main concern was nesting, and I didn't originally know there was a backend check going in. So that was a bug-concern and probably influenced my thoughts on recopying the existing pattern, but that is in now with #3546! So last thing was concurrency and IMO who cares about that as long as we check on the backend before writing to db! haha We could consider refetching tasks + invalidating animal tags to cover that on deletion/removal failure for the future... but I don't need it now.

But yah looking into the bug I am seeing.

@antsgar
Copy link
Collaborator Author

antsgar commented Dec 6, 2024

@Duncan-Brain thank you so much for testing thoroughly!! I didn't have much time honestly and I checked for an animal that did have finalized tasks and figured it was working correctly 🤦🏻‍♀️

}
const finalizedTasks = getFinalizedTasks();

return selectedInventoryIds.some((id) =>
Copy link
Collaborator

@Duncan-Brain Duncan-Brain Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@antsgar I think this would do it -- but its not pretty:

return selectedInventoryIds.some((animalOrBatchId) => {
        const {id, kind} = parseInventoryId(animalOrBatchId);
        return finalizedTasks.filter(
          ({ animals, animal_batches }: { animals: Animal[]; animal_batches: AnimalBatch[] }) => {
            const animalIds = animals.map(({ id }) => `${id}`);
            const batchIds = animal_batches.map(({ id }) => `${id}`);
            return kind === AnimalOrBatchKeys.ANIMAL ? animalIds.includes(`${id}`) : batchIds.includes(`${id}`);
          },
        ).length > 0;
      }
    );

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a PR for it if helpful -- .. removed redundant > 0

@antsgar antsgar requested a review from Duncan-Brain December 6, 2024 14:55
Copy link
Collaborator

@Duncan-Brain Duncan-Brain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-running tests but pre-approve thinking it was a flakey one

@kathyavini kathyavini requested a review from SayakaOno December 6, 2024 16:45
Copy link
Collaborator

@kathyavini kathyavini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes both the type error crash and the deletion-ablity bug that would have needed tag invalidation so I approve 👍

Just wanted to make sure @SayakaOno had a chance to take a look, too.

I do still agree in general that we want to move heavy filtering to the backend, and I would be in favour of revisiting the other solution if this looks like it's making the app slow when tasks pile up!

@kathyavini kathyavini added this pull request to the merge queue Dec 6, 2024
Merged via the queue into integration with commit 7d87bf7 Dec 6, 2024
5 checks passed
@Duncan-Brain
Copy link
Collaborator

I would be in favour of revisiting the other solution if this looks like it's making the app slow when tasks pile up!

This lines up with my understanding of optimisation 😝 : https://wiki.c2.com/?RulesOfOptimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants